import type { Test } from "@server/src/schemas/tests";
import type { Stage, Status } from "@server/src/types/allure";
import { TreeNodesTree } from "./tests-tree";

export function TestSteps({ test }: { test: Test }) {
  const data: Stage[] = [
    {
      name: "Set up",
      time: { start: 0, stop: 0, duration: 0 },
      status: "passed" as Status,
      steps: test.beforeStages ?? [],
      attachments: [],
      parameters: [],
      shouldDisplayMessage: true,
      stepsCount: 0,
      attachmentsCount: 0,
      hasContent: true,
    },
    {
      name: "Tear down",
      time: { start: 0, stop: 0, duration: 0 },
      status: "passed" as Status,
      steps: test.afterStages ?? [],
      attachments: [],
      parameters: [],
      shouldDisplayMessage: true,
      stepsCount: 0,
      attachmentsCount: 0,
      hasContent: true,
    },
  ];
  if (test.testStage) {
    data.splice(1, 0, {
      name: "Test body",
      time: { start: 0, stop: 0, duration: 0 },
      ...test.testStage,
      attachments: [],
    });
  }

  return <TreeNodesTree data={data} showLines={true} />;
}
